Skip to content

fix(id): tie serve-lock liveness to the process incarnation (#3040) - #8667

Merged
dezren39 merged 1 commit into
mainfrom
queue/5649-3040-land
Nov 11, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/5649-3040-land

Conversation

@dezren39

@dezren39 dezren39 commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #3040: the serve lock recorded only a PID and get_serve_info() tested PID existence, so a PID reused by an unrelated process made a dead serve look alive and wedged discovery on its endpoint.

ServeInfo now also records the serve process start time (Linux /proc/<pid>/stat field 22, clock ticks since boot) at lock creation; is_process_alive compares it when both sides have one and reports stale on mismatch. Locks written before this field, and platforms without a readable start time, fall back to the existing existence probe (kill(pid, 0), EPERM counts as alive, sentinel PIDs refused) unchanged.

This cherry-picks commit 2c6ff3ec85 from branch queue/5649-3040-serve-lock (a port of draft PR #4090 onto main, prepared earlier today) onto current main — PR #4090 itself was closed unmerged on 2026-11-11, which cleared this task's recorded hard-stop gate.

Tests

cargo test --lib -- test_is_process_alive test_serve_info on this branch: all pass, including the new test_is_process_alive_reused_pid regression (a live PID with an off-by-one recorded start time reads stale) and the pre-existing sentinel/dead-PID cases and ServeInfo JSON roundtrips (old locks without the field still parse via #[serde(default)]).

Fleet task 5649 (lane any-a). The task's lane row was bound to a cleared legacy opencode session (ses_e5e37c9779...; cleared 2026-11-11T01:33Z, flip refused); pickup state and the gate change are recorded on #3040.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

The serve lock recorded only a PID and get_serve_info tested PID
existence, so a PID reused by an unrelated process made a dead serve
look alive and wedged discovery on its endpoint. ServeInfo now also
records the serve process start time (Linux /proc/<pid>/stat field
22) at lock creation; is_process_alive compares it when both sides
have one and reports stale on mismatch. Locks written before this
field, and platforms without a readable start time, fall back to the
existing existence probe (kill(pid,0), EPERM counts as alive, sentinel
PIDs refused) unchanged. Ports draft PR #4090 onto current main.
Tests: cargo test test_is_process_alive — 6/6, including a new
reused-PID regression (off-by-one start time reads stale).
@dezren39
dezren39 requested a review from a team as a code owner November 11, 2026 12:11
@coderabbitai

coderabbitai Bot commented Nov 11, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 52 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 88bcc613-1390-4f3e-9bb4-23f94d0d2052
Commits

Reviewing files that changed from the base of the PR and between b8be94f and ce1874b.

Files selected for processing: 1

  • pkgs/id/src/commands/serve.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T12:14:37.694497Z ce1874b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ce1874b8ab

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +3277 to +3279
let actual = get_process_start_time(pid).expect("own start time is readable");
assert!(is_process_alive(pid, Some(actual)));
assert!(!is_process_alive(pid, Some(actual + 1)));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add property coverage with an independent start-time oracle

The regression obtains actual through the same parser used by is_process_alive, so accidentally extracting another numeric /proc/<pid>/stat field would still pass both assertions. The new parser has a meaningful invariant—extracting field 22 regardless of spaces or parentheses in comm—but only receives this self-referential example coverage. Extract the string parsing into a helper and add property tests using generated process names and an independently selected field-22 value, as required by the repository’s testing doctrine.

AGENTS.md reference: AGENTS.md:L42-L46

Useful? React with 👍 / 👎.

@dezren39

Copy link
Copy Markdown
Member Author

agent-note:v1
state: salvage-comparison
task: 17217
lane: code-a
worker: repo-worker-code
What: Salvage comparison for duplicate PR #8637 (same queue task 5649, same issue #3040 fix as this merged PR #8667), performed before closing PR #8637 as superseded by this PR.
Comparison of PR #8637 diff (pkgs/id/src/commands/serve.rs, +69/-8) against the landed commit ce1874b from this PR:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

id(serve): serve-lock staleness check tests pid existence, not serve identity — a reused pid wedges serve discovery on a dead endpoint

1 participant